<template>
    <div class="ali-pay">
        <Loading v-if="loading"></Loading>
        <!-- 使用v-html绑定返回的form -->
        <div class="form" v-html="content">

        </div>
    </div>
</template>
<script>
import Loading from './../components/Loading'
export default {
    name:'alipay',
    components:{
        Loading
    },
    data(){
        return{
            orderId:this.$route.query.orderId,
            content:'',
            loading:true
        }
    },
    mounted(){
        this.paySubmit();
    },
    methods:{
        paySubmit(){
            this.axios.post('/pay/',{
                orderId:this.orderId,
                orderName:'Vue高仿商城',
                amount:0.01,//金额
                payType:1 //1支付宝 2微信
            }).then((res)=>{
                // 支付宝支付接口是返回一个html页面,页面中有一个form,需要去触发表单的跳转
                this.content=res.content;
                setTimeout(()=>{
                    // 提交支付宝推送的表单 ,支付宝有一层网关，拿到签名重定向到收银台，再进行扫码支付
                    document.forms[0].submit();
                },100)
            })
        }
    }
}
</script>